package leetcode.mapCode.week1.k98;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * description :
 * author Ahang :
 * create : 2025-11-04 11:46
 */
public class Main {
    static private ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
    static private ArrayList<Integer> path = new ArrayList<>();
    static private boolean[] visited ;
    private static void dfs(int [][] graph ,int x ,int y){
        if (x == y) {
            ans.add(new ArrayList(path));
            return ;
        }
        for (int i =1;i<=y;i++) {
            if (graph[x][i] == 1) {
                path.add(i);
                dfs(graph, i, y);
                path.remove(path.size() - 1);
            }
        }
    }
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[][] graph = new int[n + 1][n + 1];
        visited = new boolean[n+1];
        for (int i =0 ;i<m ;i++){
            int x = scanner.nextInt();
            int y = scanner.nextInt();
            graph[x][y]=1;
        }
        path.add(1);
        dfs(graph,1,n);
        if (ans.isEmpty()){
            System.out.println(-1);
        }
        for (ArrayList<Integer> i : ans ){
            for (int j = 0;j<i.size()-1;j++){
                System.out.print(i.get(j)+" ");
            }
            System.out.println(i.get(i.size()-1));
        }
    }
}
